package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ZhwyShops;
import com.ruoyi.service.IZhwyShopsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商铺信息Controller
 * 
 * @author ruoyi
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/asset/shops")
public class ZhwyShopsController extends BaseController
{
    @Autowired
    private IZhwyShopsService zhwyShopsService;
    /**
     * 查询商铺信息列表
     */
    @PreAuthorize("@ss.hasPermi('asset:shops:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZhwyShops zhwyShops)
    {
        startPage();
        List<ZhwyShops> list = zhwyShopsService.selectZhwyShopsList(zhwyShops);
        return getDataTable(list);
    }

    /**
     * 导出商铺信息列表
     */
    @PreAuthorize("@ss.hasPermi('asset:shops:export')")
    @Log(title = "商铺信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZhwyShops zhwyShops)
    {
        List<ZhwyShops> list = zhwyShopsService.selectZhwyShopsList(zhwyShops);
        ExcelUtil<ZhwyShops> util = new ExcelUtil<ZhwyShops>(ZhwyShops.class);
        util.exportExcel(response, list, "商铺信息数据");
    }

    /**
     * 获取商铺信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('asset:shops:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zhwyShopsService.selectZhwyShopsById(id));
    }

    /**
     * 新增商铺信息
     */
    @PreAuthorize("@ss.hasPermi('asset:shops:add')")
    @Log(title = "商铺信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZhwyShops zhwyShops)
    {
        return toAjax(zhwyShopsService.insertZhwyShops(zhwyShops));
    }

    /**
     * 修改商铺信息
     */
    @PreAuthorize("@ss.hasPermi('asset:shops:edit')")
    @Log(title = "商铺信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZhwyShops zhwyShops)
    {
        return toAjax(zhwyShopsService.updateZhwyShops(zhwyShops));
    }

    /**
     * 删除商铺信息
     */
    @PreAuthorize("@ss.hasPermi('asset:shops:remove')")
    @Log(title = "商铺信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zhwyShopsService.deleteZhwyShopsByIds(ids));
    }

    @GetMapping("/Did/{id}")
    public List selectByDid(@PathVariable Long  id){
        List<ZhwyShops> list = zhwyShopsService.selectByDid(id);
        return list;
    }


    @GetMapping("/DCode/{id}/{code}")
    public List selectByDidAndCode(@PathVariable Long id, @PathVariable String code){
        List list = zhwyShopsService.selectByDidAndCode(id, code);
        return list;
    }



    @GetMapping("/state/{id}")
    public int selectState(@PathVariable int id){
        int i = zhwyShopsService.selectState(id);
        System.out.println("============"+i);
        return i;
    }
}
